package org.xtetris;

public class Shape {
	final static int EMPTY = 0;
	
	/**     
	 * 	    ---
	 * 	   |   |
	 *  --- --- ---
	 * |   |   |   |
	 *  --- --- ---
	 */
	public final static int[][][] SHAPE1 = {
		{
			{0 , 1 , 0},
			{1 , 1 , 1}
		},
		{
			{1 , 0 },
			{1 , 1 },
			{1 , 0 }
		},
		{
			{1, 1 , 1},
			{0 , 1 , 0}
		},
		{
			{0 , 1},
			{1 , 1},
			{0 , 1}
		}
	};
	
	
	/**
	 *  ---------
	 * |    |    |
	 *  ---------
	 * |    |    |
	 *  ---------
	 */
	public final static int[][][] SHAPE2 = {
		{
			{1,  1},
			{1 , 1}
		}
	};
	
	
	/**
	 *      --- ---
	 *     |   |   |
	 *  --- --- ---
	 * |   |   |
	 *  --- ---
	 */
	public final static int[][][] SHAPE3 = {
		{
			{0 , 1, 1},
			{1 , 1, 0},
		},
		{
			{1 , 0},
			{1 , 1},
			{0 , 1}
		}
	};
	
	/**
	 *  --- ---
	 * |   |   |
	 *  --- --- ---
	 *     |   |   |
	 *      --- ---
	 * 
	 */
	public final static int[][][] SHAPE4 = {
		{
			{1, 1 , 0},
			{0 , 1 , 1}
		},
		{
			{0 , 1} , 
			{1 , 1} ,
			{1 , 0} ,
		},
	};
	
	/**
	 *  --- --- --- ---
	 * |   |   |   |   |
	 *  --- --- --- ---
	 * 
	 */
	public final static int[][][] SHAPE5 = {
		{
			{1 , 1 , 1 , 1}
		},
		{
			{1},
			{1},
			{1},
			{1},
		}
		
	};
	
	
	/** ---
	 * |   |
	 *  ---
	 * |   |
	 *  --- ---
	 * |   |   |
	 *  --- ---
	 * 
	 */
	public final static int[][][] SHAPE6 = {
		{
			{1 , 0},
			{1 , 0},
			{1 , 1}
		},
		{
			{1 , 1 , 1},
			{1 , 0 , 0}
		},
		{
			{1 , 1},
			{0 , 1},
			{0 , 1}
		},
		{
			{0 , 0 , 1},
			{1 , 1 , 1},
		}
	};
	
	/**
	 *      ---
	 *     |   |
	 *      ---
	 *     |   |
	 *  --- ---
	 * |   |   |
	 *  --- ---
	 * 
	 */
	public final static int[][][] SHAPE7 = {
		{
			{0, 1},
			{0, 1},
			{1, 1},
		},
		{
			{1 , 0 , 0},
			{1 , 1 , 1}
		},
		{
			{1, 1 },
			{1 ,0 },
			{1, 0 },
		},
		{
			{1 , 1 , 1},
			{0 , 0 , 1}
		}
	};
	
	public final static int[][][][] SHAPES = {SHAPE1 , SHAPE2 , SHAPE3 , SHAPE4 , SHAPE5 ,SHAPE6 , SHAPE7};
	
	int color;
	final int[][][] shape;
	
	int x , y;
	
	int state;
	public Shape(int[][][] shape , int color , int x , int y){
		this.shape = shape;
		this.color = color;
		this.x = x;
		this.y = y;
		this.state = 0;
	}
	
	public Shape(Shape shape){
		this.shape = shape.shape;
		this.color = shape.color;
		this.x = shape.x;
		this.y = shape.y;
	}
	
	void rotate(){
		state = nextState();
	}
	
	int nextState(){
		return (state + 1) % shape.length;
	}
	
	static int getNumberOfShapes(){
		return SHAPES.length;
	}
}
